// pages/main/main.js
//引入封装号的 request
const http = require("../../utils/http")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pushList: [], //推荐数据
    likeList: [], //猜你喜欢数据
    imageList: [], //轮播图数据
    activList: [], //活动数据
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true, //轮播是否有小圆点
    vertical: false, //false 横向   true 纵向
    autoplay: true, //自动播放
    interval: 2000, //动画时间
    duration: 1000, //间隔时间
    circular: true, //衔接动画  
    swiperIndex: 0, //轮播图下标
  },
  goBox(ev){
    console.log(ev);
  },
  //跳转内容页，并传参
  goItem(ev) {
    console.log(ev);
    const id = ev.currentTarget.dataset.index;
    //跳转内容页并传参
    wx.navigateTo({
      url: '/pages/item/item?id=' + id,
    })
  },
  //获取当前轮播图下标
  changeSwiper(ev) {
    this.setData({
      swiperIndex: ev.detail.current
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 推荐数据
    http.request('product/product/getProductRecommendUser', {
      desc: false,
      orderBy: "top",
      pageNow: 1,
      pageSize: 20,
      seller_user_id: "4bc4027c645343f09a964b5c2e9f875b"
    }, "post").then(res => {
      this.setData({
        pushList: res.data
      })
    }).catch(err => {
      console.log(err);
    })
    // 猜你喜欢数据
    http.request('product/product/guessYouLike', '', 'get').then(res => {
      this.setData({
        likeList: res.data
      })
    }).catch(err => {
      console.log(err);
    })
    //轮播图数据
    http.request('product/banner/getBySeller/4bc4027c645343f09a964b5c2e9f875b', '', 'get').then(res => {
      this.setData({
        imageList: res.data
      })
    }).catch(err => {
      console.log(err);
    })
    //招募活动数据
    http.request('requirement/request/getMatchedProducts', {
      desc: false,
      orderBy: "outtime",
      pageSize: 100,
      product_type: 2
    }, 'post').then(res => {
      console.log(res);
      this.setData({
        activList: res.data.matchedProducts
      })
    }).catch(err => {
      console.log(err);
    })
  },
  //停止轮播图,在页面隐藏前的钩子函数onHide
  onHide(){
    this.setData({autoplay:false})
  },
  onShow(){
    this.setData({autoplay:true})
  }

})